<!--  -->
<template>
  <div class="buttom flex column grow">
    <yn-title>
      <template slot="icon">
        <img
          src="../images/spkc.png"
          @error="imageHandler(path + '/client/ylHome/images/spkc.png', $event)"
        />
      </template>
      <div slot="right" @click="link" style="cursor: pointer">查看更多>></div>
    </yn-title>
    <div class="box flex column grow">
      <div class="noMore flex column grow" v-if="marketList.length == 0">
        <div class="noMoreBg">暂无数据</div>
      </div>
      <table v-if="marketList.length > 0">
        <thead>
          <tr>
            <td>星期</td>
            <td>直播时间</td>
            <td>课程名称</td>
            <td>直播状态</td>
          </tr>
        </thead>
        <tbody>
          <tr
            v-for="item in marketList"
            :key="item.liveId"
            @click="link(item.channelId)"
          >
            <td>{{ item.week }}</td>
            <td>{{ item.period }}</td>
            <td>{{ item.channelName }}</td>
            <td :class="{ cur: item.status == 1 }">{{ item.type }}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
import { queryShowYeMarketChargeLiveList } from "../api/index";
import format from "date-fns/format";
import * as fn from "../script/utils";
import { CLIENT } from "@/common/const";

export default {
  data() {
    return {
      marketList: [],
      path: CLIENT,
      imageHandler: fn.imageHandler,
    };
  },

  components: {},

  computed: {},

  mounted() {
    this.queryShowYeMarketChargeLiveList();
  },

  methods: {
    link(id) {
      id = typeof id == "string" ? id : "";
      window.prompt(
        "",
        `up://["user.info",${Date.now()},{"type":"video","data":{"url":"${
          this.path
        }/client/toLiveVip.htm?playId=${id}"}}]`
      );
    },
    async queryShowYeMarketChargeLiveList() {
      const { token } = fn.getUrlParams();
      const { data } = await queryShowYeMarketChargeLiveList({
        productId: window.localStorage.getItem("productId"),
        clientCentralToken: token,
      }).then((back) => {
        if (back.status == 1) {
          let data = back.data;
          this.marketList = data.map((item) => {
            item.period =
              format(new Date(item.beginTime), "HH:mm") +
              "-" +
              format(new Date(item.endTime), "HH:mm");
            item.type = ["尚未开始", "正在直播"][item.status];
            item.week = [
              "周日",
              "周一",
              "周二",
              "周三",
              "周四",
              "周五",
              "周六",
            ][new Date(item.beginTime).getDay()];
            return item;
          });
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.buttom {
  height: 27.6%;
  color: #fff;
  padding: 20px 0 14px;
  box-sizing: border-box;
  .box {
    overflow-y: auto;
    .noMore {
      flex-direction: row; /* 子元素横向排列 */
      justify-content: center; /* 相对父元素水平居中 */
      align-items: center; /*  子元素相对父元素垂直居中 */
      .noMoreBg {
        color: #bcbfc4;
        font-size: 16px;
      }
    }
  }
  table {
    line-height: 41px;
    text-align: center;
    width: 100%;
    font-size: 16px;
    margin: 20px 0 0;
    font-weight: 400;
    color: #bcbfc4;
    border: 1px solid #323337;
    box-sizing: border-box;

    td {
      border: 1px solid #323337;
    }
    thead {
      line-height: 42px;
      background: #232429;
    }
    tbody {
      line-height: 38px;
      .cur {
        color: #ff8a1b;
      }
      tr:hover {
        background: #323337;
      }
    }
  }
}
.right {
  width: 811px;
  .list {
    margin: 20px 0 30px 0;
    .item {
      margin-right: 20px;
      .vImg {
        width: 100%;
        height: 189px;
        overflow: hidden;
        background: #fff;
      }
      .vInfo {
        line-height: 38px;
        color: #bcbfc4;
        font-weight: 400;
        .name {
          font-size: 20px;
        }
        .time {
          font-size: 18px;
        }
      }
    }
  }
}
</style>
